home *** CD-ROM | disk | FTP | other *** search
- Path: belle.bork.com!news
- From: root@belle.bork.com (BOFH)
- Newsgroups: comp.lang.c,comp.unix.programmer
- Subject: Re: Q: '\n' character - strtok trick
- Followup-To: comp.lang.c,comp.unix.programmer
- Date: 3 Apr 1996 10:40:32 -0600
- Organization: Bork Systems Group
- Message-ID: <4ju9m0$nq9@belle.bork.com>
- References: <31616F63.481D@lava.weeg.uiowa.edu> <4jrvv3$ask@aimnet.aimnet.com> <828493319snz@genesis.demon.co.uk> <828542474.7672@tertio.demon.co.uk>
- NNTP-Posting-Host: belle.bork.com
- X-Newsreader: TIN [UNIX 1.3 BETA-950824-color PL0]
-
- alord@tertio.co.uk wrote:
- : Although the behaviour of strtok() is well defined I try to avoid it like the
- : plague because it uses a static area to maintain state. If another function
- : happens to call it between successive invocations then your screwd.
-
- Well, yes it does use a static data area to store it's state, but that
- doesn't matter. When you call the function this way, strtok will return
- a pointer to the beginning of the string that it chopped a newline off
- of, AND will insert a NULL character into the location of the newline.
- After it returns, you are done. Your string has had the newline taken
- off, and you are done with strtok. strtok will internally remember where
- it last took a delimiter off, but it only needs it when strtok is called
- with a NULL buffer anyway.
-
- The only problem with this is that you could be in the middle of parsing
- a string with strtok, and then you attempted to strtok(buffer,...), which
- would definately cause a problem.
-
- My $0.02.
-
-
- Randy Scott <scottr@belle.bork.com>
-